import CryptoJS from "crypto-js";
// key 必须为16位
const securityKey = "IUHYINKWEFWTXQPZ";

/**
* AES加密
* @param {Object} content 待加密的数据
* @param {Object} secretKey 密钥
*/
function encrypt (content,secretKey) {
　　let key = CryptoJS.enc.Utf8.parse(secretKey);
    let srcs = CryptoJS.enc.Utf8.parse(content);
    let encrypted = CryptoJS.AES.encrypt(srcs, key, { mode:CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
    return encrypted.toString();
}
/** * AES解密
 * @param {Object} encryptStr 待解密的数据
 * @param {Object} secretKey    密钥
 */
function decrypt (encryptStr,secretKey) {
	let key = CryptoJS.enc.Utf8.parse(secretKey);
	let decrypt = CryptoJS.AES.decrypt(encryptStr, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
	return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}

export{
    encrypt,
    decrypt,
    securityKey
};